package com.gla.service;

import com.gla.dao.WalletMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class WalletService {

    @Resource
    WalletMapper walletMapper;

    public Double getMoney(Integer user_id) {
        Double money = walletMapper.selectByUserId(user_id);
        return money;
    }

    public Integer update(Integer user_id, Double number) {
        Double money = getMoney(user_id);
        if(money!=null) {
            if(money + number >= 0) {
                walletMapper.update(user_id,money + number);
                return 0;
            } else {
                return -1;
            }
        } else {
            return -2;
        }
    }
}
